Description
This manual connection member function signals a connected logical semaphore. Each time the semaphore is signaled, its value is modified. Blocked requesters whose conditions are met, are unblocked. Before reading this topic, we would recommend familiarity with Manual Connections and Logical Semaphores.
The operation that is applied to the semaphore's existing value depends on the 'rule'. The following rules are supported;
CLP_EQ_RULE
New value = key1;
CLP_AND_RULE
New value = Old Value & key1;
CLP_OR_RULE
New value = Old Value | key1;
CLP_XOR_RULE
New value = Old Value ^ key1;
CLP_MOD_RULE
New value = (Old Value + key1) % key2;
Prototype
Uns Signal( Int key1,
Int key2,
Uns rule,
Int *oldValue );
Parameters
key1
First modifier key.
key2
Second modifier key.
rule
Modifying operation (see above).
oldValue
Address of a signed integer that will be set to the value that the semaphore had prior to modification. If NULL is passed then this parameter is ignored (old value not assigned).
Return Value
This function returns logical TRUE if the semaphore is successfully signaled, or FALSE otherwise.
Example
The following code will increment a logical semaphore and return the previous value. Since the operation is atomic, and works across a network, this technique is often used as a means of generating unique IDs.
Int uniqueId;
Aux1_IdLsm1Cxn().Signal(
1, // Add one
to the existing value
N, // Wrap
with Modulo N
CLP_MOD_RULE, // Apply modulo operation
&uniqueId ); // Populate unique Id with old value